﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using TMDT.BusinessObjects;

namespace TMDT.BusinessLogic
{
    public class NoiDungSanPhamManager
    {
        public bool Add(NoiDungSanPham entity)
        {
               return BusinessHelper.CapNhatDuLieu(new Command
                                                    {
                                                        CommandText = "spNoiDungSanPhamInsert",
                                                        CommandType = CommandType.StoredProcedure,
                                                        Parameter = new[]
                                                                        {
                                                                            new SqlParameter("@IDSanPham",
                                                                                             entity.IDSanPham),
                                                                            new SqlParameter("@IDThuocTinh",
                                                                                             entity.IDThuocTinh),
                                                                            new SqlParameter("@NoiDung", entity.NoiDung)
                                                                        }
                                                    });
        }

        public bool Update(NoiDungSanPham entity)
        {
            return BusinessHelper.CapNhatDuLieu(new Command
                                                    {
                                                        CommandText = "spNoiDungSanPhamUpdate",
                                                        CommandType = CommandType.StoredProcedure,
                                                        Parameter = new[]
                                                                        {
                                                                            new SqlParameter("@IDSanPham",
                                                                                             entity.IDSanPham),
                                                                            new SqlParameter("@IDThuocTinh",
                                                                                             entity.IDThuocTinh),
                                                                            new SqlParameter("@NoiDung", entity.NoiDung)
                                                                        }
                                                    });
        }

        public bool Remove(Guid idSanPham)
        {
            return BusinessHelper.CapNhatDuLieu(new Command
                                                    {
                                                        CommandText = "spNoiDungSanPhamDelete",
                                                        CommandType = CommandType.StoredProcedure,
                                                        Parameter = new[]
                                                                        {
                                                                            new SqlParameter("@IDSanPham",idSanPham), 
                                                                        }
                                                    });
        }

        public List<NoiDungSanPham> GetNoiDungSanPham()
        {
            List<NoiDungSanPham> noiDungSanPham = new List<NoiDungSanPham>();
            DataSet dtSet = new DataSet();
            dtSet = BusinessHelper.TruyVanDuLieu(new Command
                                                     {
                                                         CommandText = "select * from NoiDungSanPham",
                                                         CommandType = CommandType.Text,
                                                     });
            foreach (DataRow row in dtSet.Tables[0].Rows)
            {
                noiDungSanPham.Add(NoiDungSanPham.Convert(row));
            }
            return noiDungSanPham;
        }

        public List<NoiDungSanPham> GetNoiDungByIDSanPham(Guid idSanPham)
        {
            List<NoiDungSanPham> noiDungSanPham = new List<NoiDungSanPham>();
            DataSet dtSet = new DataSet();
            dtSet = BusinessHelper.TruyVanDuLieu(new Command
                                                     {
                                                         CommandText =
                                                             "select * from NoiDungSanPham where IDSanPham = @IDSanPham",
                                                         CommandType = CommandType.Text,
                                                         Parameter = new[]
                                                                         {
                                                                             new SqlParameter("IDSanPham", idSanPham),
                                                                         }
                                                     });
            foreach (DataRow row in dtSet.Tables[0].Rows)
            {
                noiDungSanPham.Add(NoiDungSanPham.Convert(row));
            }
            return noiDungSanPham;
        }
    }
}
